<div class="layui-form" lay-filter="layuiadmin-form-module" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">子系统名称</label>
        <div class="layui-input-inline">
            <script type="text/html" template="">
                <select id="sys" name="topLevelId" lay-verify="required" lay-filter="sys" onfocus="alert(222)">
                    <option value=""></option>
                    {{# if(d.params.gnmkId){ }}
                    {{# layui.each(layui.data('menu').sys_lis,function(index,item){ }}
                    <option value={{item.gnmkId}} {{ (d.params.topLevelGnmk.gnmkName=== item.gnmkName ?
                    'selected' : '') }}>{{item.gnmkName}}</option>
                    {{# }); }}
                    {{#}else{ }}
                    {{# layui.each(layui.data('menu').sys_lis,function(index,item){ }}
                    <option value={{item.gnmkId}}>{{item.gnmkName}}</option>
                    {{# }); }}
                    {{# } }}
                </select>
            </script>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-inline">
            <script type="text/html"  template>
                <select id="menu" name="secondLevelId" lay-verify="required" lay-filter="menu">
                    {{# if(d.params.gnmkId){ }}
                    {{# layui.each(layui.data('menu').menu_obj[d.params.topLevelGnmk.gnmkId],function(index,item){ }}
                    <option value={{item.gnmkId}} {{ (d.params.secondLevelGnmk.gnmkId=== item.gnmkId ?
                    'selected' : '') }}>{{item.gnmkName}}</option>
                    {{# }); }}
                    {{# } }}
                </select>

            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块名称</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="gnmkName" value="{{ d.params.gnmkName || '' }}" lay-verify="required"
                       placeholder="请输入功能模块" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">服务地址</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="iframe" value="{{ d.params.iframe || '' }}" lay-verify="required"
                       placeholder="请输入服务地址" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="LAY-module-front-submit" value="确认" class="layui-btn mybtn">
        </div>
    </div>
</div>

<script>

    layui.use('form', function () {
        var form = layui.form, $ = layui.$, appoint_menu_lis;
        form.on('select(sys)', function (data) {
            var option_str = '<option value=""></option>'
            var sys_lis = layui.data('menu').sys_lis
            $.ajax({
                // url: "./json/menu.js?v={{ layui.admin.v }}", // 测试接口
                url: layui.setter.hostAddr+`/portal/gnmk/gnmkbypid?pid=${data.value}`,
                type: "GET",
                dataType: "json",
                async:false,
                beforeSend: function (XMLHttpRequest) {
                    XMLHttpRequest.setRequestHeader("Authorization", layui.data('layuiAdmin').Authorization);
                },
                success: function (res) {
                    for (var i in res.data) {
                        option_str = option_str + `<option value="${res.data[i].gnmkId}" >${res.data[i].gnmkName}</option>`
                    }
                    console.log(res)
                    console.log(option_str)
                }
            })
            console.log(option_str)
            $('#menu').empty()
            $('#menu').append(option_str)
            form.render()
        })
    })

    function menudeal() {
        debugger
        var sys_name = $("#sys").val()
        var option_str = ''
        var appoint_menu_lis = layui.data('menu').menu_obj[sys_name]
        console.log(appoint_menu_lis)
        for (var i in appoint_menu_lis) {
            option_str = option_str + `<option value=${appoint_menu_lis[i]} >${appoint_menu_lis[i]}</option>`
            // <option value={{item.GWDM}} {{ (d.params.gwName=== item.GWMC ? 'selected' : '') }}>{{item.GWMC}}</option>
        }
        $("#menu").empty()
        $("#menu").append(option_str)

    }

</script>

